//展示SKU
$('.getsku').on('click',function(){
    var googsid = $(this).attr('googsid');

    ajax("post","/googs/get-googsattr",{googsid:googsid},
        function success(data){
            var dIv="<div class='b-div'><h4 class='b-h4'>SKU</h4><div class='b-btn'>";
            dIv += "<table class=' table  table-striped table-bordered table-advance table-hover'>";
            dIv += '<tr>';
            dIv += '<th>属性</th>';
            dIv += '<th>原价</th>';
            dIv += '<th>折后价</th>';
            dIv += '<th>库存</th>';
            dIv += '</tr>';
            $(data.data).each(function ($key,$val) {
                dIv += '<tr>';
                dIv += '<td>'+$val.attr_value+'</td>';
                dIv += '<td>'+$val.original_price+'</td>';
                dIv += '<td>'+$val.discount_price+'</td>';
                dIv += '<td>'+$val.inventory+'</td>';
                dIv += '</tr>'
            })
            dIv+='</table>'
            dIv += "<input type='button' onclick='closeattr()' value='取消' class='b-cancel'></div></div>";
            $("body").append(dIv);
        }
    );

});
function closeattr() {
    $('.b-div').hide();
}
//三级联动
$('.oneclass').change(function () {
    var classid = $(".oneclass option:selected").val();
    $('.twoclass').html('');
    $('.threeclass').html('');
    changeclassAjax('.twoclass',classid,'二')
})

$('.twoclass').change(function () {
    var classid = $(".twoclass option:selected").val();
    $('.threeclass').html('');
    changeclassAjax('.threeclass',classid,'三')
})
function changeclassAjax(calsss,id,num) {
    $.ajax({
        'url': '/googs/get-tree',
        'type': 'POST',
        'dataType': 'json',
        'data': {id:id},
        'success': function (data) {
            if (data.code != 200) {
                layer.alert(data.msg);
                return false;
            } else {
                var option = '<option value="0">请选择'+num+'级分类</option>';
                $.each(data.data,function(indexe,value){
                    option += '<option value="'+value.id+'">'+value.tree_name+'</option>'
                });
                console.log(calsss);
                $(calsss).append(option);
            }
        }
    });
}